﻿#define _CRT_SECURE_NO_WARNINGS
#include "Stack.h"
void STInit(ST* ps)
{
	ps->capacity = 0;
	ps->a = NULL;
	ps->top = 0;
}
void STDestroy(ST* ps)
{
	if (ps->a)
		free(ps->a);
	STInit(ps);
}

// ջ
void STPush(ST* ps, STDataType x)
{
	if (ps->top == ps->capacity)
	{
		int newcapacity = ps->capacity == 0 ? 4 : 2 * ps->capacity;
		ps->a = (STDataType*)malloc(sizeof(STDataType) * newcapacity);
		if (ps->a == NULL)
		{
			perror("malloc");
			exit(0);
		}
	}
	ps->a[(ps->top)++] = x;
}
void STPop(ST* ps)
{
	assert(ps->top > 0);
	ps->top--;
}
STDataType STTop(ST* ps)
{
	return ps->a[ps->top - 1];
}
int STSize(ST* ps)
{
	return ps->top;
}
bool STEmpty(ST* ps)
{
	return ps->top == 0;
}